package com.oig.sys.log.event;

import com.oig.sys.log.dto.SysAuditLogDto;
import com.oig.sys.log.feign.SysAuditLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

@Slf4j
public class SysAuditLogEventListener {

    private final SysAuditLogService sysAuditLogService;

    public SysAuditLogEventListener(SysAuditLogService sysAuditLogService){
        this.sysAuditLogService = sysAuditLogService;
    }

    @Async
    @Order
    @EventListener(SysAuditLogEvent.class)
    public void addJpaAuditLog(SysAuditLogEvent event){
        log.debug("触发记录审计日志事件");
        SysAuditLogDto auditLogDto = (SysAuditLogDto) event.getSource();
        sysAuditLogService.addSysAuditLog(auditLogDto);
    }

}
